<template>
	<view class="wrap bg-white">
		<Navbar title="请选择委派人" />
		<u-form :model="form" ref="uForm" :label-width="100">
			<u-form-item label="委派人" required prop="delegate">
				<UserSelect :multiple="false" v-model="form.delegate"/>
			</u-form-item>
			<u-button type="primary" :loading="loading" :disabled="loading" @click="submit">提交</u-button>
		</u-form>
	</view>
</template>

<script>
	import UserSelect from '@/components/user-select.vue'
	import { postAction,getAction } from '@/api/manage.js'
	import { CURY_TYPE } from '@/utils/constant.js'
	import Navbar from '@/components/navbar.vue'
	export default {
		components:{ UserSelect,Navbar },
		data() {
			return {
				form: {
					delegate:''
				},
				rules: {
					delegate: [
						{ 
							required: true, 
							message: '请选择委派人', 
							trigger: ['change','blur'],
						}
					]
				},
				urlObj:{
					save: '/camunda/task/delegate/',
				},
				loading:false,
				id:''
			}
		},
		methods: {
			submit(){
				this.loading = true
				this.$refs.uForm.validate().then(valid => {
					this.save()
				}).catch(errors => {
					setTimeout(() => {
						this.loading = false
					},1000)
				})
			},
			save(){
				postAction(this.urlObj.save+this.id+'/'+this.form.delegate).then(res => {
					const data = res.data
					if(data.success){
						this.$modal.msgSuccess('操作成功')
						setTimeout(() => {
							this.$Router.back(2)
						},1000)
					}else{
						this.$modal.msgError(data.message)
					}
				}).catch(errors => {
					setTimeout(() => {
						// uni.hideLoading();
						this.loading = false
					},1000)
				})
			},
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules)
		},
		onLoad(options) {
			const { id } =this.$Route.query
			this.id = id
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #ffffff;
	}
	.wrap{
		padding-left: 10px;
		padding-right: 10px;
	}
</style>
